//引入重置样式
require('../../assets/css/reset.css')

//引入公共样式
require('../../assets/css/property.css')

//加载自己的样式
require('./course.less')

const { render } = require('less')
//引入tabbar渲染函数
// const renderTabbar = require('../../../utils/tabbar')

// 导入navbar
const navbar = require('../../../utils/navbar')

//导入ajax工具函数
const request = require('../../../utils/request')

window.onload=()=>{
    // 引入navbar
    navbar('course')

    //服务器地址 要拼接图片地址
  const API = 'http://fitness.h5.itsource.cn:3701'

  // 获取dom
  const newcourse = document.querySelector('#newcourse')
  const courselist = document.querySelector('#courselist')
  
  function getData(){
    // 获取数据
    request.get('/api/train/courseList')
    .then(res=>{
      console.log(res.data);
      let{errno,data}=res.data

      if(errno===0){
        // 渲染
      render(data)
    }
    })
  }
  
  //初始化发请求
  getData()

  function render(data){
    //最新课程数据
    const data1 = data[0]

    let html1 =`
      <h3>最新课程</h3>
      <div class="coursebox">
        <img class="img" src="${API + data1.imgurl}" alt="">
        <div class="info">
            <div class="name">${data1.name}</div>
            <div class="desc">${data1.desc}</div>
       </div>
    `
    newcourse.innerHTML=html1
   
  }
 
  //获取课程列表数据
  const data2 = data.filter((v, i) => i !== 0)
  //列表html
  const html2 = `
    ${data2
      .map(
        v => `
      
    `
      )
      .join('')}
  `

  }